<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>
<title>后台用户设置</title>
<style type="text/css">
</style>
<script type="text/javascript">
	var gender;//性别
	var blackListFlag;//会员状态
	var userTrust;//脱管状态
	var findUserName;//开单中心
	var data;
	var flag = true;
	var reloadFlag;
	init();
	//校验
	$.extend($.fn.validatebox.defaults.rules, {
		
	});
	$(function() {
		//会员状态下拉框
		$('#isBlackListFlag').combobox({
			onLoadSuccess : function() {
				var data = $('#isBlackListFlag').combobox('getData');
				if (data) {
					$("#isBlackListFlag").combobox('select', data[0].id);
				}
			}
		});
		//脱管状态下拉框
		$('#isUserTrust').combobox({
			onLoadSuccess : function() {
				var data = $('#isUserTrust').combobox('getData');
				if (data) {
					$("#isUserTrust").combobox('select', data[0].id);
				}
			}
		});
		//开单中心下拉框
		$('#findUserName').combobox({
			onLoadSuccess : function() {
				var data = $('#findUserName').combobox('getData');
				if (data) {
					$("#findUserName").combobox('select', data[0].userAccount);
				}
			}
		});
		
		//查询按钮
		$("#search").click(function() {
			var params = {
					branchId:$("#findUserName").combobox("getValue"),
					cellPhone:$("#cellPhone1").val(),
					memberName:$("#memberName").val(),
					blackListFlag:$("#isBlackListFlag").combobox("getValue"),
					userTrust:$("#isUserTrust").combobox("getValue"),
			};
			$("#tt").datagrid('load', params);
		});
		
		//新增
		$("#add").click(function() {
			window.location.href="${ctx}/member/goMemberAdd";
		});
		
		$("#edit").click(function() {
			var row = $('#tt').datagrid('getSelected');
			if (!row) {
				$.messager.alert("请选择一行", "请选择一行", "error");
				return;
			}else{
				var id = row.id;
				window.location.href="${ctx}/member/goMemberAdd?id="+id;
			}
		});
		
		$("#export").click(function() {
			
			window.location.href="${ctx}/member/export";
		});
		
		
		//移出黑名单
		$("#moveOutBlack").click(function() {
			doBlack(0);
		});
		//添加黑名单
		$("#addBlack").click(function() {
			doBlack(1);
		});
		
		//托管
		$("#trust").click(function() {
			trust(1);
		});
		//取消托管
		$("#removetrust").click(function() {
			trust(0);
		});

		//调整账户
		$("#tiaozheng").click(function() {
			var row = $('#tt').datagrid('getSelected');
			if (!row) {
				$.messager.alert("请选择一行", "请选择一行", "error");
				return;
			}
			var id = row.id;
			var role = row.userRole;
			reloadFlag = false;
			$("#fm").form('load', '${ctx}/member/gett?id=' + id);
			$("#dlg").dialog("open");
			$(".panel-title").text('账户调整');
		});
		
		
		
		
		////调整账户表单的提交
		$('#fm').form({
			url : '${ctx}/member/save?acc='+1,
			onSubmit : function() {
				var id = $("#id").val();
				if (id != null && id != "") {
				} else {
					return $(this).form('validate');
				}
			},
			success : function(data) {
				data = eval("(" + data + ")");
				if (data.result == 1) {
					$("#dlg").dialog('close');
					$.messager.alert("成功", "成功", "info", reload);
				} else {
					$.messager.alert("失败：", data.msg, "error");
				}
			}
		});
		init();
	});

	function init() {
		$.ajax({
			url:'${ctx}/enum?enumName=Gender',			
			cache:true,
			async:false,
			success:function(data){
				gender = data;
			}
			
		});
		
		$.ajax({
			url:'${ctx}/enum?enumName=MemberType',			
			cache:true,
			async:false,
			success:function(data){
				blackListFlag = data;
			}
		});
		
		$.ajax({
			url:'${ctx}/enum?enumName=MemberTrust',			
			cache:true,
			async:false,
			success:function(data){
				userTrust = data;
			}
		});
		//开单中心
		$.ajax({
			url:'${ctx}/member/findUserName',			
			cache:true,
			async:false,
			success:function(data){
				findUserName = data;
			}
		});
	};

	function saved() {
		$('#fm').submit();
	};
	
	

	function reload(closeFlag) {
		if (reloadFlag) {
			$("#fm").form('clear');
		}
		if (closeFlag) {
			$("#dlg").dialog('close');
		}
		$("#tt").datagrid('reload');
	}
	
	//黑名单调整,g功能完成了
	function doBlack(blackFlag){
		var rows = $('#tt').datagrid('getSelections');
		if(rows.length==0){
				$.messager.alert("请选择一行","请选择数据","error");
				return ;
		}
		var allId=0;
		for(var i=0; i<rows.length; i++){
			allId = allId+","+rows[i].id;
		}
		$.messager.confirm("确定","你确定将选择的人加入黑名单么?",function(r){
			if(r) {
				$.ajax({
					url:'${ctx}/member/findMemberListById',
					data:{"allId":"("+allId+")","blackFlag":blackFlag},
					dateType:'json',
					success:function(data){
						if(data.result==1){
							$.messager.alert("操作结果","成功","info",reload);
						}else{
							$.messager.alert("失败",data.msg,"error");
						}
					}
				})
			}
		})
	}
	//托管,ok
	function trust(trustFlag){
		var rows = $('#tt').datagrid('getSelections');
		if(rows.length==0){
				$.messager.alert("请选择一行","请选择数据","error");
				return ;
		}
		var allId=0;
		for(var i=0; i<rows.length; i++){
			allId = allId+","+rows[i].id;
		}
		$.messager.confirm("确定","你确定将选择的人加入托管么?",function(r){
			if(r) {
				$.ajax({
					url:'${ctx}/member/updateMemberTrust',
					data:{"allId":"("+allId+")","flag":trustFlag},
					method:'POST',
					dateType:'json',
					success:function(data){
						if(data.result==1){
							$.messager.alert("操作结果","成功","info",reload);
							
						}else{
							$.messager.alert("失败",data.msg,"error");
						}
					}
				})
			}
		})
	}
	//关闭弹框
	function closeDlg() {
		$("#tt").datagrid('reload');
		$('#dlg').dialog('close');
	};
	
	//表格中显示的性别
	function getGender(value, row, index) {
		for ( var g in gender) {
			if (gender[g].id == value) {
				return gender[g].name;debugger
			}
		}
		return value;
	} 
	
	//表格中显示的性别Gender
	function getGender(value, row, index) {
		for ( var g in gender) {
			if (gender[g].id == value) {
				return gender[g].name;debugger
			}
		}
		return value;
	} 
	//会员状态blackListFlag
	function getBlackListFlag(value, row, index) {
		for ( var g in blackListFlag) {
			if (blackListFlag[g].id == value) {
				return blackListFlag[g].name;
			}
		}
		return value;
	} 
	//脱管状态userTrust
	function getUserTrust(value, row, index) {
		for ( var g in userTrust) {
			if (userTrust[g].id == value) {
				return userTrust[g].name;
			}
		}
		return value;
	} 
	//开单中心
	function getBranch(value,row,index){
		for(var g in findUserName){
			if(findUserName[g].userAccount==value){
				return findUserName[g].username;
			}
		}
		return value;
	}
	//隔行变色
	function rowStyle(index, row) {
		if (index % 2 == 0) {
			return 'background-color:lightcyan;';
		}
	}
	
	//鼠标悬停显示提示
	function showTips(value, row, index) {
		var content = '';
		if (value != null && String(value) != '') {
			content = '<span title="' + value + '" class="note" >' + value
					+ '</span>';
		}
		return content;
	}
	
	//table里面的查看会员详情
	function formatOper(val,row,index){
		if (val != null && val != "") {
			return '<a href="javascript:audit(\''+row.id+'\');" title="'+val+'&#10;点击查看会员详情">'+val+'</a>';  
		}
	}
	//查看会员详情请求地址
	function audit(id){
		window.location.href="${ctx}/member/goMemberInfo?id="+id;
	}
</script>
</head>
<body>
<div class="jianju">
	<h3>会员列表</h3>
	<div id="tb" style="height: auto" class="datagrid-toolbar">
		<div>
			<a id="add" href="#" class="easyui-linkbutton button" iconcls="icon-add" plain="false">新增</a>
			<a id="edit" href="#" class="easyui-linkbutton button" iconcls="icon-edit" plain="false">编辑</a>
			<a id="addBlack" href="#" class="easyui-linkbutton button" iconcls="icon-rub" plain="false">加入黑名</a>
			<a id="moveOutBlack" href="#" class="easyui-linkbutton button" iconcls="icon-yichu" plain="false">移出黑名单</a>
			<a id="trust" href="#" class="easyui-linkbutton button" iconcls="icon-rub" plain="false">托管</a>
			<a id="removetrust" href="#" class="easyui-linkbutton button" iconcls="icon-yichu" plain="false">取消托管</a>
			<a id="tiaozheng" href="#" class="easyui-linkbutton button" iconcls="icon-edit" plain="false">账户调整</a>
			<a id="export" href="#" class="easyui-linkbutton button" iconcls="icon-daochu">导出</a>
		</div>
		<hr>
		<div>
			<label style="margin-left: 0;">开单中心：</label> 
				<select id="findUserName" class="easyui-combobox" style="width: 100px" 
					mode="remote" url="${ctx}/member/findUserName?f=true" valueField="userAccount"
					textField="username" method="get" editable="false" panelHeight="auto">
				</select>
			<label style="margin-left: 15px;">会员手机号：</label>
				<input id="cellPhone1" class="easyui-textbox" style="width: 100px">
			<label style="margin-left: 15px;">会员姓名：</label>
				<input id="memberName" class="easyui-textbox" style="width: 100px">
			<label style="margin-left: 15px;">会员状态：</label>
				<select id="isBlackListFlag" class="easyui-combobox" style="width: 100px"
					mode="remote" url="${ctx}/enum?enumName=MemberType&all=true"
					valueField="id" textField="name" method="get" editable="false"
					panelHeight="auto">
				</select>
			<label style="margin-left: 15px;">托管状态：</label>
				<select id="isUserTrust" class="easyui-combobox" style="width: 100px"
					mode="remote" url="${ctx}/enum?enumName=MemberTrust&all=true"
					valueField="id" textField="name" method="get" editable="false"
					panelHeight="auto">
				</select>
			<a id="search" href="#" class="easyui-linkbutton button" style="margin-left: 15px;" iconCls="icon-search">查询</a>
		</div>
	</div>
	
	<table id="tt" class="easyui-datagrid"
		url="${ctx}/member/list" title=""
		style="width: 98%; minWidth: 1000px;" iconCls="icon-save"
		rownumbers="true" pagination="true" pageList="[10,20,30,40]"
		method="get" toolbar="#tb" singleSelect="false" fitColumns="true"
		idField="id" rowStyler="rowStyle"
		onLoadSuccess:function(data){
              $(".note").tooltip({
                  onShow:function(){
                      $(this).tooltip('tip').css({ 
                          width:'300',
                          boxShadow: '1px 1px 3px #292929'        
                      });
                  }
              });
           } >
		<thead>
			<tr>
				<th field="ck" checkbox="true"
					style="width: 3%"></th>
				<th data-options="field:'memberName',align:'center',formatter:formatOper"
					style="width: 12%">会员姓名</th>
				<th data-options="field:'cellPhone',align:'center',formatter:showTips"
					style="width: 15%">会员手机号</th>
				<th data-options="field:'branchId',align:'center',formatter:getBranch"
					style="width: 20%">开单中心</th>
				<th data-options="field:'gender',align:'center',formatter:getGender"
					style="width: 10%">性别</th>
				<th data-options="field:'idCardNumber',align:'center',formatter:showTips"
					style="width: 20%">身份证号码</th>
				<th data-options="field:'blackListFlag',align:'center',formatter:getBlackListFlag"
					style="width: 10%">会员状态</th>
				<th data-options="field:'userTrust',align:'center',formatter:getUserTrust"
					style="width: 10%">托管状态</th>
			</tr>
		</thead>
	</table>
</div>

<div id="dlg" class="easyui-dialog" style="width:500px;padding:10px 20px"
	closed="true" buttons="#dlg-buttons" modal="true">
	<div class="ftitle"></div>
	<form id="fm" method="post" class="form-horizontal" role="form">
		<input type="hidden" id = "id" name="id">
		<div class="fitem form-group">
			<label class="col-sm-3 control-label">总收益：</label>
			<div class="col-sm-4">
				<input name="totalIncome" class="easyui-validatebox easyui-textbox" style="width:200px">
			</div>
		</div>
		<div class="fitem form-group">
			<label class="col-sm-3 control-label">余额：</label>
			<div class="col-sm-4">
				<input name="avaibleCash" class="easyui-validatebox easyui-textbox" style="width:200px">
			</div>
		</div>
		
		<div class="fitem form-group">
			<label class="col-sm-3 control-label">乐花：</label>
			<div class="col-sm-4">
				<input name="cusumeCash" class="easyui-validatebox easyui-textbox" style="width:200px">
			</div>
		</div>
		
		<div class="fitem form-group"> 	
			<label class="col-sm-3 control-label">贴心宝：</label>
			<div class="col-sm-4">
					<input name="investmentCash" class="easyui-validatebox easyui-textbox" style="width:200px">
			</div>
		</div>
		
		<div class="fitem form-group">
			<label class="col-sm-3 control-label">税费：</label>
			<div class="col-sm-4">
				<input name="tax" class="easyui-validatebox easyui-textbox" style="width:200px">
			</div>
		</div>
	</form>
</div>
<div id="dlg-buttons">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:saved()">保存</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:reload(true);">取消</a>
</div>
</body>
</html>